home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / turbovis / ptg120co.zip / PREAPP.PAS < prev    next >
Pascal/Delphi Source File  |  1993-11-06  |  9KB  |  349 lines

  1. { Created : 1991-09-05
  2.  
  3. Functions and procedures used by the PtGen created application
  4.  
  5. $Author: Berend_de_Boer $
  6. $Date: 93/05/20 23:00:55 $
  7. $Revision: 1.1 $
  8.  
  9. Last changes :
  10. 93-02-01  Made completely TV2.0 aware
  11. 93-03-06  Renamed to PREAPP.PAS
  12.           Internationalized by making use of string resources
  13. }
  14.  
  15. {$I DEFINES.DEF}
  16.  
  17. {$F+,O+,X+,R-,Q-,S-,V-,D+}
  18. unit PreApp;
  19.  
  20. interface
  21.  
  22. uses Objects, Drivers, Views, Menus,
  23.      {$IFDEF Editor}
  24.      Editors,
  25.      {$ENDIF}
  26.      {$IFDEF TVTool}         {* you can only compile PreApp when TVTool *}
  27.      TVApp,                  {* is defined in DEFINES.DEF when you have *}
  28.      {$ENDIF}                {* the TVTool pack of Richard Hansen       *}
  29.      App;
  30.  
  31.  
  32. {$IFDEF Editor}
  33. const
  34.   hcEditor = 2700;
  35. {$ENDIF}
  36.  
  37. type
  38.   PPreAppStatusLine = ^TPreAppStatusLine;
  39.   TPreAppStatusLine = object(TStatusLine)
  40.     function Hint(AHelpCtx : word) : string;  virtual;
  41.   end;
  42.  
  43.   PPreApp = ^TPreApp;
  44. {$IFDEF TVTool}
  45.   TPreApp = object(TbxApplication)
  46. {$ELSE}
  47.   TPreApp = object(TApplication)
  48. {$ENDIF}
  49. {$IFDEF Editor}
  50.     constructor Init;
  51. {$ENDIF}
  52. {$IFDEF BufferedPrinter}
  53.     procedure Idle;  virtual;
  54. {$ENDIF}
  55. {$IFDEF Help}
  56.     procedure GetEvent(var Event: TEvent);  virtual;
  57. {$IFNDEF TVTool}
  58.     function  GetPalette: PPalette;  virtual;
  59. {$ENDIF TVTool}
  60. {$ENDIF Help}
  61.     procedure OutOfMemory;  virtual;
  62.   end;
  63.  
  64. {$IFDEF Help}
  65. var
  66.   HFileName : FNameStr;
  67. {$ENDIF}
  68.  
  69. {$IFDEF Editor}
  70. var
  71.   ClipWindow : PEditWindow;
  72.  
  73. function OpenEditor(FileName: FNameStr; Visible: Boolean) : PEditWindow;
  74. {$ENDIF}
  75.  
  76.  
  77. implementation
  78.  
  79. uses Dialogs,
  80.      {$IFDEF Editor}
  81.      StdDlg,
  82.      {$ENDIF}
  83.      {$IFDEF Help}
  84.      HelpFile,
  85.      {$ENDIF}
  86.      {$IFDEF BufferedPrinter}
  87.      BufPrinter,
  88.      {$ENDIF}
  89.      Dos, BBFile, BBUtil, BBDlg, BBStrRes;
  90.  
  91.  
  92. {$I STRINGS.INC}
  93.  
  94.  
  95. function TPreAppStatusLine.Hint(AHelpCtx : word) : string;
  96. begin
  97.   Hint := Strings^.Get(AHelpCtx);
  98. end;
  99.  
  100.  
  101. {$IFDEF Editor}
  102. function CreateFindDialog: PDialog;
  103. var
  104.   D: PDialog;
  105.   Control: PView;
  106.   R: TRect;
  107. begin
  108.   R.Assign(0, 0, 38, 12);
  109.   D := New(PDialog, Init(R, rsGet(seFind)));
  110.   with D^ do
  111.   begin
  112.     Options := Options or ofCentered;
  113.  
  114.     R.Assign(3, 3, 32, 4);
  115.     Control := New(PInputLine, Init(R, 80));
  116.     Insert(Control);
  117.     R.Assign(2, 2, 15, 3);
  118.     Insert(New(PLabel, Init(R, rsGet(seTextToFind), Control)));
  119.     R.Assign(32, 3, 35, 4);
  120.     Insert(New(PHistory, Init(R, PInputLine(Control), 10)));
  121.  
  122.     R.Assign(3, 5, 35, 7);
  123.     Insert(New(PCheckBoxes, Init(R,
  124.       NewSItem(rsGet(seCase),
  125.       NewSItem(rsGet(seWholeWords), nil)))));
  126.  
  127.     R.Assign(14, 9, 24, 11);
  128.     Insert(New(PButton, Init(R, 'O~K~', cmOk, bfDefault)));
  129.     Inc(R.A.X, 12); Inc(R.B.X, 12);
  130.     Insert(New(PButton, Init(R, 'Cancel', cmCancel, bfNormal)));
  131.  
  132.     SelectNext(False);
  133.   end;
  134.   CreateFindDialog := D;
  135. end;
  136.  
  137.  
  138. function CreateReplaceDialog: PDialog;
  139. var
  140.   D: PDialog;
  141.   Control: PView;
  142.   R: TRect;
  143. begin
  144.   R.Assign(0, 0, 40, 16);
  145.   D := New(PDialog, Init(R, rsGet(seReplace)));
  146.   with D^ do
  147.   begin
  148.     Options := Options or ofCentered;
  149.  
  150.     R.Assign(3, 3, 34, 4);
  151.     Control := New(PInputLine, Init(R, 80));
  152.     Insert(Control);
  153.     R.Assign(2, 2, 15, 3);
  154.     Insert(New(PLabel, Init(R, rsGet(seTextToFind), Control)));
  155.     R.Assign(34, 3, 37, 4);
  156.     Insert(New(PHistory, Init(R, PInputLine(Control), 10)));
  157.  
  158.     R.Assign(3, 6, 34, 7);
  159.     Control := New(PInputLine, Init(R, 80));
  160.     Insert(Control);
  161.     R.Assign(2, 5, 12, 6);
  162.     Insert(New(PLabel, Init(R, rsGet(seNewText), Control)));
  163.     R.Assign(34, 6, 37, 7);
  164.     Insert(New(PHistory, Init(R, PInputLine(Control), 11)));
  165.  
  166.     R.Assign(3, 8, 37, 12);
  167.     Insert(New(PCheckBoxes, Init(R,
  168.       NewSItem(rsGet(seCase),
  169.       NewSItem(rsGet(seWholeWords),
  170.       NewSItem(rsGet(sePromptOnReplace),
  171.       NewSItem(rsGet(seReplaceAll), nil)))))));
  172.  
  173.     R.Assign(17, 13, 27, 15);
  174.     Insert(New(PButton, Init(R, 'O~K~', cmOk, bfDefault)));
  175.     R.Assign(28, 13, 38, 15);
  176.     Insert(New(PButton, Init(R, 'Cancel', cmCancel, bfNormal)));
  177.  
  178.     SelectNext(False);
  179.   end;
  180.   CreateReplaceDialog := D;
  181. end;
  182.  
  183.  
  184. function DoEditDialog(Dialog: Integer; Info: Pointer): Word; far;
  185. var
  186.   R: TRect;
  187.   T: TPoint;
  188. begin
  189.   case Dialog of
  190.     edOutOfMemory:
  191.       DoEditDialog := MessageBox(rsGet(sMemory),
  192.         nil, mfError + mfOkButton, hcNoContext);
  193.     edReadError:
  194.       DoEditDialog := MessageBox(rsGet(seErrReading),
  195.         @Info, mfError + mfOkButton, hcNoContext);
  196.     edWriteError:
  197.       DoEditDialog := MessageBox(rsGet(seErrWriting),
  198.         @Info, mfError + mfOkButton, hcNoContext);
  199.     edCreateError:
  200.       DoEditDialog := MessageBox(rsGet(seErrCreating),
  201.         @Info, mfError + mfOkButton, hcNoContext);
  202.     edSaveModify:
  203.       DoEditDialog := MessageBox(rsGet(seSave),
  204.         @Info, mfInformation + mfYesNoCancel, hcNoContext);
  205.     edSaveUntitled:
  206.       DoEditDialog := MessageBox(rsGet(seSaveUntitled),
  207.         nil, mfInformation + mfYesNoCancel, hcNoContext);
  208.     edSaveAs:
  209.       DoEditDialog := ExecDialog(New(PFileDialog, Init('*.*',
  210.         rsGet(seSaveAs), rsGet(sName), fdOkButton, 101)), Info);
  211.     edFind:
  212.       DoEditDialog := ExecDialog(CreateFindDialog, Info);
  213.     edSearchFailed:
  214.       DoEditDialog := MessageBox(rsGet(seStringNotFound),
  215.         nil, mfError + mfOkButton, hcNoContext);
  216.     edReplace:
  217.       DoEditDialog := ExecDialog(CreateReplaceDialog, Info);
  218.     edReplacePrompt:
  219.       begin
  220.         { Avoid placing the dialog on the same line as the cursor }
  221.         R.Assign(0, 1, 40, 8);
  222.         R.Move((Desktop^.Size.X - R.B.X) div 2, 0);
  223.         Desktop^.MakeGlobal(R.B, T);
  224.         Inc(T.Y);
  225.         if TPoint(Info).Y <= T.Y then
  226.           R.Move(0, Desktop^.Size.Y - R.B.Y - 2);
  227.         DoEditDialog := MessageBoxRect(R, rsGet(seReplaceThis),
  228.           nil, mfYesNoCancel + mfInformation, hcNoContext);
  229.       end;
  230.   end;
  231. end;
  232.  
  233.  
  234. function OpenEditor(FileName: FNameStr; Visible: Boolean): PEditWindow;
  235. var
  236.   P: PView;
  237.   R: TRect;
  238. begin
  239.   DeskTop^.GetExtent(R);
  240.   P := Application^.ValidView(New(PEditWindow,
  241.     Init(R, FileName, wnNoNumber)));
  242.   P^.HelpCtx := hcEditor;
  243.   if not Visible then P^.Hide;
  244.   DeskTop^.Insert(P);
  245.   OpenEditor := PEditWindow(P);
  246. end;
  247.  
  248. constructor TPreApp.Init;
  249. var
  250.   R: TRect;
  251. begin
  252.   if Strings = nil then  begin
  253.     PrintStr('You should load strings using BBStrRes.LoadStrings. Program halts.');
  254.     Halt(1);
  255.   end;
  256.   inherited Init;
  257.   DisableCommands([cmSave, cmSaveAs, cmCut, cmCopy, cmPaste, cmClear,
  258.     cmUndo, cmFind, cmReplace, cmSearchAgain]);
  259.   EditorDialog := DoEditDialog;
  260.   ClipWindow := OpenEditor('', False);
  261.   if ClipWindow <> nil then
  262.   begin
  263.     Clipboard := ClipWindow^.Editor;
  264.     Clipboard^.CanUndo := False;
  265.   end;
  266. end;
  267. {$ENDIF}
  268.  
  269. {$IFDEF Help}
  270. procedure TPreApp.GetEvent(var Event: TEvent);
  271. var
  272.   W: PWindow;
  273.   HFile: PHelpFile;
  274.   HelpStrm: PBufStream;
  275.   D : DirStr;
  276.   N : NameStr;
  277.   E : ExtStr;
  278.   FileName : string;
  279. const
  280.   HelpInUse: Boolean = False;
  281. begin
  282.   inherited GetEvent(Event);
  283.   case Event.What of
  284.     evCommand : if (Event.Command = cmHelp) and not HelpInUse then  begin
  285.         HelpInUse := TRUE;
  286.         FSplit(ParamStr(0), D,N,E);
  287.         FileName := FSearch(HFileName, D+';'+GetEnv('PTGINPUT')+';'+GetEnv('PATH'));
  288.         if FileName = ''
  289.          then  PrintError(rsGet1(sHelpFileNotFound, longint(@HFileName)), hcNoContext)
  290.          else  begin
  291.            HelpStrm := New(PBufStream, Init(FileName, stOpenRead, 1024));
  292.            HFile := New(PHelpFile, Init(HelpStrm));
  293.            if HelpStrm^.Status <> stOk
  294.             then  begin
  295.               PrintError(rsGet1(word(HelpStrm^.Status), longint(@HFileName)), hcNoContext);
  296.               Dispose(HFile, Done);
  297.             end
  298.             else  begin
  299.               W := New(PHelpWindow,Init(HFile, GetHelpCtx));
  300.               if ValidView(W) <> nil then  begin
  301.                 ExecView(W);
  302.                 Dispose(W, Done);
  303.               end;
  304.               ClearEvent(Event);
  305.             end;
  306.          end;
  307.